//泛型可以传入多个<T,U>；返回可以 T|U 代表或的关系
function hello<T, U>(data: T, data2: U): T | U {
  console.log(data, data2);
  return Date.now() % 2 ? data : data2;
}

hello<string, number>("abc", 1);
hello<number, boolean>(123, true);

//泛型接口
// interface HelloInterface<T> {
//   (data: T): T;
// }
interface PersonInterfacec<T, U> {
  name: string;
  age: number;
  sex: T;
  extraInfo: U;
}

type Jobtype = {
  title: string;
  company: string;
};

let pt: PersonInterfacec<string, Jobtype> = {
  name: "张三",
  age: 18,
  sex: "男",
  extraInfo: {
    title: "前端",
    company: "百度",
  },
};

//泛型类
class Personkk<T> {
  constructor(public name: string, public age: number, public extraInfo: T) {}
  speak() {
    console.log(`我是学生，我的名字${this.name},今年${this.age}`);
    console.log(this.extraInfo);
  }
}
type Jobtypec = {
  title: string;
  company: string;
};
const pk = new Personkk<Jobtypec>("tom", 12, {
  title: "前端",
  company: "百度",
});
